home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / HEAP_UTL / TPSTACK / TPSTACK.DOC < prev    next >
Text File  |  1988-06-25  |  3KB  |  79 lines

  1. TPSTACK - Unit for Monitoring Heap and Stack Usage
  2. -------------------------------------------------------
  3. Brian Foley
  4. TurboPower Software
  5. 6/88
  6. Version 1.00
  7. Released to the public domain
  8.  
  9. Overview
  10. ------------------------------------------------------------------------------
  11. TPSTACK allows you to accurately monitor a program's stack and heap usage
  12. simply by adding TPSTACK to the beginning of the program's USES list. The
  13. following program demonstrates how to use it:
  14.  
  15.   program TpStackTest;
  16.     {-Simple program to test TpStack}
  17.   uses
  18.     TpStack,
  19.     CRT;
  20.   var
  21.     P : Pointer;
  22.  
  23.     procedure StackEater;
  24.       {-Use some stack space}
  25.     var
  26.       BigArray : array[1..12331] of Byte; {this is on the stack}
  27.     begin
  28.       {delay a moment to insure that TpStack sees what we've used}
  29.       Delay(10);
  30.     end;
  31.  
  32.   begin
  33.     {use some stack and heap space}
  34.     GetMem(P, 56789);
  35.     StackEater;
  36.   end.
  37.  
  38. If you run this little demo program, you'll see that TpStack automatically
  39. displays the amount of heap and stack space used by the program when it ends.
  40.  
  41. Normally it is just this easy. In some cases, however, you may want or need to
  42. handle the reporting of results yourself. If so, you would set
  43. ReportStackUsage to False and call CalcStackUsage to obtain the necessary
  44. information.
  45.  
  46. If you want to disable stack monitoring temporarily--when executing other
  47. programs, for example--you can call RestoreInt8 to disable it and InstallInt8
  48. to reenable it.
  49.  
  50. TpStack can monitor only a single stack segment, normally the one in use when
  51. the program began. If you need to use it in a program that uses an alternate
  52. stack (a memory resident program, perhaps), you'll have to initialize three
  53. global variables before the first time that you switch to that stack. Here's
  54. an example:
  55.  
  56.    {disable TpStack momentarily}
  57.    RestoreInt8;
  58.    {OurSS has the stack segment to watch}
  59.    OurSS := AlternateStackSegment;
  60.    {InitialSP has the value of "SP" when the program began}
  61.    InitialSP := TopOfAlternateStack;
  62.    {LowestSP has the lowest value of SP so far, same as InitialSP at first}
  63.    LowestSP := InitialSP;
  64.    {reactivate TpStack}
  65.    InstallInt8;
  66.  
  67. Finally, in order to improve the accuracy of its results, TpStack reprograms
  68. the timer chip so that it can get control of the machine over 1000 times a
  69. second. For this reason, TpStack should not be used in programs that
  70. themselves reprogram the chip, or in programs that are using the PEP unit in
  71. Turbo Analyst. If you wish to change the rate at which samples are taken, you
  72. can call the SetSampleRate routine:
  73.  
  74.    {select 100 samples per second}
  75.    SetSampleRate(100);
  76.  
  77. The minimum value allowed is 18 samples per second, which is what the rate
  78. would be TpStack didn't reprogram the timer.
  79.